package com.tem.controller;

import com.alibaba.fastjson.JSON;
import com.tem.domain.User;
import com.tem.interceptor.MyInterceptor;
import com.tem.service.IUserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.swing.text.html.FormSubmitEvent;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;

/**
 * @Author: tiger
 * @Date:2018/4/28
 * @Description:User控制层
 */
@RestController
public class UserController {
    private final Logger logger = Logger.getLogger(UserController.class);
    @Autowired
    private IUserService iUserServiceImpl;

    /**
     * @Author:Tiger
     * @Date:2018/5/7 20:08
     * @Params:[userId]用户编号
     * @Returns:java.lang.Object
     * @Description:根据编号查询
     */
    @RequestMapping("/getUserById")
    public Object getUserById(Long userId) {
        User user = iUserServiceImpl.getUserById(userId);
        return user;
    }


    /**
     * @Author:Tiger
     * @Date:2018/5/7 20:07
     * @Params:[]
     * @Returns:java.lang.Object
     * @Description:查询所有user
     */
    @RequestMapping("/findUsers")
    public Object findUsers() {
        List<User> userList = iUserServiceImpl.findUsers();
        logger.info("userList" + JSON.toJSONString(userList));
        return userList;
    }

    /**
     * @Author:Tiger
     * @Date:2018/5/7 20:09
     * @Params:[user]
     * @Returns:java.lang.Object
     * @Description:添加用户
     */
    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    public void addUser(User user) {
        iUserServiceImpl.addUser(user);
    }

    /**
     * @Author:Tiger
     * @Date:2018/5/7 21:23
     * @Params:[user]
     * @Returns:void
     * @Description:修改用户信息
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public void updateById(User user) {
        iUserServiceImpl.updateById(user);
    }

}
